<?php


namespace app\demo\home;

usethink\facade\Db;

/**
 * 前台搜索控制器
 * @package app\demo\admin
 */
class Search extends Common
{
    /**
     * 搜索列表
     * @param string $keyword 关键词
     * @author dragonlhp <1458485514@qq.com>
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index($keyword = '')
    {
        if ($keyword == '') $this->error('请输入关键字');
        $map = [
            ['demo_document.trash', '=', 0],
            ['demo_document.status', '=', 1],
            ['demo_document.title', 'like', "%$keyword%"]
        ];

        $data_list = Db::view('demo_document', true)
            ->view('admin_user', 'username', 'demo_document.uid=admin_user.id', 'left')
            ->where($map)
            ->order('create_time desc')
            ->paginate(config('list_rows'));

        $this->assign('keyword', $keyword);
        $this->assign('lists', $data_list);
        $this->assign('pages', $data_list->render());

        return $this->fetch(); // 渲染模板
    }
}
